package com.timliu.ui;
import java.util.LinkedList;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.timliu.activity.R;




public class ListBase extends BaseAdapter {
private static final String TAG = "ListBase";
	
	
	private Context context;	
	private LayoutInflater inflater;
	private LinkedList<String> mListItems;
	
	
	
	public ListBase(Context context,LinkedList<String> mListItems ) {
        this.context = context;
        this.mListItems = mListItems;
        inflater = LayoutInflater.from(context);
    }

	@Override
	public int getCount() {
		if(mListItems != null)
            return mListItems.size();
		return 0;
	}

	@Override
	public Object getItem(int position) {
		if(mListItems != null && mListItems.size() != 0)
            return mListItems.get(position);
		return null;
	}

	@Override
	public long getItemId(int position) {
		if(mListItems != null && mListItems.size() != 0)
			return  position;
//		return  mListItems.get(position).id;
		return -1;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Log.i(TAG, "getView()-->");
		
		Holder holder = null;

    	if (convertView == null) {
    		
    		convertView = inflater.inflate(R.layout.list_item_test, null);
    		
    		holder = new Holder();    		
    		
    		holder.textview = (TextView)convertView.findViewById(R.id.textview);
    		
    		
        	convertView.setTag(holder);
    	}else{
    		
    		holder = (Holder)convertView.getTag();
    	}
    	
    	
    	String mNewsList = (String)getItem(position);
		
    	
		
		if(mNewsList != null){
			holder.textview.setText(mNewsList);
			
			
					
			
		}
		return convertView;
	}
	
	static class Holder{
    	
    	TextView textview;
    	
    }

}